﻿using System;
using System.Text;
using System.Threading.Tasks;
using SuperSocket.Command;

namespace Demo005
{
    
    
    public class HoldingRegistersCommandFilterAttribute:CommandFilterAttribute
    {
        // public async override ValueTask<bool> OnCommandExecutingAsync(CommandExecutingContext commandContext)
        // {
        //     var pack=  commandContext.Package as ModbusPackageInfo;
        //
        //     
        //     Console.WriteLine("OnCommandExecutingAsync");
        //     
        //     await Task.Delay(0);
        //     return true;
        // }
        //
        // public async override ValueTask OnCommandExecutedAsync(CommandExecutingContext commandContext)
        // {
        //         
        //         var pack=  commandContext.Package as ModbusPackageInfo;
        //
        //         if (pack.Key != 0x03)
        //         {
        //             await  commandContext.Session.SendAsync(Encoding.UTF8.GetBytes("不符合规范"));
        //              
        //         }
        //        
        //         await Task.Delay(0);
        //     Console.WriteLine("OnCommandExecutedAsync");
        // }
        public override bool OnCommandExecuting(CommandExecutingContext commandContext)
        {
            Console.WriteLine("Bye bye");
            return true;
        }

        public override void OnCommandExecuted(CommandExecutingContext commandContext)
        {
            Console.WriteLine("Hello");
        }
    }
}